package com.attendance.sz.local;

import android.content.Context;
import android.util.Log;

import com.attendance.sz.db.DBHandler;
import com.attendance.sz.utils.Version;

import java.util.ArrayList;
import java.util.List;

public class DBConstants {
	/**
	 * Used to create create database table and delete database table interface..
	 */
	private interface ITable {
		/** Generation create the SQL database table */
		String produceCreateSQL();
	}

	/** System context */
	public static Context context;
	/** Database operation object */
	public static DBHandler dbHandler;

	static final String DATABASE_NAME = "com.attendance.db";
	static final int DATABASE_VERSION = Version.getVersionCode();
	static final int ID = 0;// Table id, said the primary key every table

	static List<String> DB_CREATE_SQL;
	public static final String[] TABLE_NAMES = { "card_record"};

	/**
	 * The names of the table array subscript, when the call for more intuitive
	 */
	public static final int TABLE_CARD_RECORD = 0; 
   
	
	static {
		
		DB_CREATE_SQL = new ArrayList<String>();

		CardRecord cardRecord = new CardRecord();
		DB_CREATE_SQL.add(cardRecord.produceCreateSQL());

	}
	
	/**================ account ======================*/
	public static class CardRecord implements ITable {
		/**
		 * add by martrin 20150801 增加device_no号设备号(如:12) 
		   uploadFlag是否上传此条记录的标志(0--没有上传,1--已上传) Demo 其它可以存的备注
		 */
		/**==Table column name==*/
		public static final String[] COLUMNS = { "id","card_no", "line_no","name"
			,"card_type","department","create_time","device_no","uploadFlag","upload_fail_count"};
				

		/**==Table the index number (starting from 0)==*/
		public static final int card_no = 1;
		public static final int line_no = 2;
		public static final int name = 3;
		public static final int card_type = 4;
		public static final int department = 5;
		public static final int create_time = 6;
		public static final int device_no = 7;
		public static final int uploadFlag = 8;
		public static final int upload_fail_count = 9;

		@Override
		public String produceCreateSQL() {
			final String sql = "CREATE TABLE IF NOT EXISTS "
					+ TABLE_NAMES[TABLE_CARD_RECORD] + "(" + COLUMNS[ID]+ " INTEGER PRIMARY KEY AUTOINCREMENT,"
					+ COLUMNS[card_no] + " TEXT NOT NULL ," 
					+ COLUMNS[line_no] + " TEXT NOT NULL ," 
					+ COLUMNS[name] + " TEXT NOT NULL ," 
					+ COLUMNS[card_type] + " TEXT NOT NULL ," 
					+ COLUMNS[department] + " TEXT NOT NULL ,"
					+ COLUMNS[create_time] + " TEXT NOT NULL ,"
					+ COLUMNS[device_no] + " TEXT NOT NULL ,"
					+ COLUMNS[uploadFlag] + " TEXT NOT NULL ,"
	                + COLUMNS[upload_fail_count] + " TEXT NOT NULL)";
			
			Log.d(getClass().getSimpleName(), " createSQL = " + sql);






			
			return sql;
		}
	}
	
}
